/**
* AutoSWF - Cody Cushing. March 26, 2009
* Copyright (c) 2009 Cody Cushing
* No use restrictions. Maintain this notice in all versions. 
**/

package com.autoswf.core
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;

	/**
	 * Allows events passed up the chain to be dispatched. The clone method is 
	 * not called on events, beware.
	 */
	public class ChainLinkDispatcher extends ChainLink implements IEventDispatcher
	{
		protected var dispatcher:EventDispatcher;
		
		public function ChainLinkDispatcher(id:String)
		{
			super(id);
			
			dispatcher = new EventDispatcher();
		}
		
		/**
		 * If the transport object is an event dispatch it before passing it up.
		 */
		override public function sendUpChain(param:*):void
		{
			var transport:Transport = Transport(param);
			if(transport.message is Event)
			{
				var event:Event = transport.message;
				dispatcher.dispatchEvent(event);
			}
			
			notifyParents(param);
		}

		
		/* dispatcher composite */
		public function addEventListener(type:String, listener:Function, useCapture:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void
		{
			dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference)
		}
		
		public function removeEventListener(type:String, listener:Function, useCapture:Boolean=false):void
		{
			dispatcher.removeEventListener(type, listener, useCapture);
		}
		
		public function dispatchEvent(event:Event):Boolean
		{
			return dispatcher.dispatchEvent(event);
		}
		
		public function hasEventListener(type:String):Boolean
		{
			return dispatcher.hasEventListener(type);
		}
		
		public function willTrigger(type:String):Boolean
		{
			return dispatcher.willTrigger(type);
		}
		
	}
}